/**
 * Created by zhouli on 2019/4/16
 */
import axios from 'axios';
import {deepFullCopy, messages} from 'share/common';

/*
* @params menu 前端所有菜单列表，一级二级
* */
export function getAllMenus(_menu) {
  console.log(_menu);
  let menu = deepFullCopy(_menu);
  let dataC = menu.map && menu.map((item) => {
    if (item.subMenu && item.subMenu.length) {
      item.subMenu = item.subMenu.map(item => {
        return {
          en: messages(`menu.${item.key}`, {}, "en"),
          zh: messages(`menu.${item.key}`, {}, "zh"),
          icon: item.icon,
          key: item.key,
          admin: item.admin,
          tenant: item.tenant,
          company: item.company
        }
      })
    }
    return {
      en: messages(`menu.${item.key}`, {}, "en"),
      zh: messages(`menu.${item.key}`, {}, "zh"),
      key: item.key,
      icon: item.icon,
      subMenu: item.subMenu,
      admin: item.admin,
      tenant: item.tenant,
      company: item.company
    }
  })
  let params = {
    dataC
  };
  return new Promise((resolve, reject) => {
    axios({
      url: "http://localhost:8032/menus",
      method: 'POST',
      data: params,
    })
    .catch((res)=>{
      console.log(res)
    })
  })
}
